﻿using Microsoft.AspNetCore.Mvc;
using Queer.Model.Param.Weixin;
using Queer.Util.Model;
using Senparc.Weixin;
using Senparc.Weixin.WxOpen.AdvancedAPIs.Sns;
using System.Threading.Tasks;

namespace Queer.WebApi.Areas.WeixinOpen.MainManage
{
    /// <summary>
    /// 主要控制器
    /// </summary>
    public class MainController : BaseWeixinOpenController
    {
        [HttpPost]
        public async Task<TData> OnLogin([FromBody] WeixinOpenUserModel model)
        {
            var jsonResult = SnsApi.JsCode2Json(WxOpenAppId, WxOpenAppSecret, model.code);
            var obj = new TData();

            if (jsonResult.errcode == ReturnCode.请求成功)
            {
                obj.Tag = 1;
                obj.Message = jsonResult.errmsg;
                return obj;
            }
            else
            {
                obj.Message = jsonResult.errmsg;
                return obj;
            }
        }
    }
}